# -*- mode: python ; coding: utf-8 -*-

import sys
import os
from PyInstaller.utils.hooks import collect_data_files

block_cipher = None

# 获取项目根目录的绝对路径
ROOT_DIR = os.path.abspath(os.getcwd())

# 定义 poppler 路径
POPPLER_PATH = os.path.join(ROOT_DIR, 'tools', 'poppler')

# 确保 poppler 目录存在
if not os.path.exists(POPPLER_PATH):
    raise FileNotFoundError(
        f"Poppler 目录不存在: {POPPLER_PATH}\n"
        "请按照以下步骤安装：\n"
        "1. 创建 tools/poppler 目录\n"
        "2. 下载 poppler: https://github.com/oschwartz10612/poppler-windows/releases\n"
        "3. 解压文件到 tools/poppler 目录"
    )

# 定义需要包含的数据文件
added_files = [
    (POPPLER_PATH, 'tools/poppler'),  # 使用绝对路径
]

a = Analysis(
    ['src/main.py'],
    pathex=[ROOT_DIR],
    binaries=[],
    datas=added_files,
    hiddenimports=[
        'PyQt6.QtCore',
        'PyQt6.QtGui',
        'PyQt6.QtWidgets',
        'PyPDF2',
        'pdf2image',
        'reportlab',
        'docx2pdf',
        'comtypes',
        'win32com',
        'pythoncom'
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)

pyz = PYZ(
    a.pure,
    a.zipped_data,
    cipher=block_cipher
)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='PDF工具箱',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,  # 保持True以查看错误信息
    disable_windowed_traceback=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
) 